<template>
  <div class="dia">
    <el-dialog
      v-model="dialogVisible"
      title="爆管分析"
      width="600px"
      draggable
      :modal="false"
      :close-on-click-modal="false"
      :destroy-on-close="true"
    >
      <div class="con">
        <div class="head">
          <el-form :inline="true" :model="formInline">
            <!-- <el-form-item label="管网类别">
              <el-select
                v-model="formInline.lb"
                placeholder="请选择"
                clearable
                style="width: 100px"
              >
                <el-option label="燃气" value="燃气" />
              </el-select>
            </el-form-item>
            <el-form-item label="阀门">
              <el-select
                v-model="value2"
                multiple
                collapse-tags
                placeholder="请选择"
                style="width: 100px"
              >
                <el-option
                  v-for="item in optionsFm"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item> -->
            <el-form-item>
              <el-button type="primary" @click="clickBtn('新增爆管点')"
                >新增爆管点</el-button
              >
              <el-button @click="clickBtn('清除结果')">清除结果</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="body">
          <el-tabs type="border-card">
            <el-tab-pane label="上游阀门">
              <div class="body-card" v-if="tableData.point?.cldh">
                <div class="item">
                  <div class="fl">
                    <span class="i">1</span>
                    <span class="t">{{ tableData.point.cldh }}</span>
                    <span class="s">{{ tableData.point.tz }}</span>
                  </div>
                  <div class="fr">
                    <img
                      @click="clickBtn('定位', tableData.point.geom)"
                      src="@/assets/icon/bgfx_dw.png"
                    />
                  </div>
                </div>
              </div>
            </el-tab-pane>
            <el-tab-pane label="下游阀门">
              <div class="body-card" v-if="tableData.rqPointList?.length > 0">
                <div
                  class="item"
                  v-for="(item, index) in tableData.rqPointList"
                  :key="item.id"
                >
                  <div class="fl">
                    <span class="i">{{ index + 1 }}</span>
                    <span class="t">{{ item.cldh }}</span>
                    <span class="s">{{ item.tz }}</span>
                  </div>
                  <div class="fr">
                    <img
                      @click="clickBtn('定位', item.geom)"
                      src="@/assets/icon/bgfx_dw.png"
                    />
                  </div>
                </div>
              </div>
            </el-tab-pane>
            <el-tab-pane label="影响线路">
              <div class="body-card" v-if="tableData.rqLineList?.length > 0">
                <div
                  class="item"
                  v-for="(item, index) in tableData.rqLineList"
                  :key="item.id"
                >
                  <div class="fl">
                    <span class="i">{{ index + 1 }}</span>
                    <span class="t"
                      >{{ item.startPoint }} -- {{ item.endPoint }}</span
                    >
                    <span class="s">{{ item.type }}</span>
                  </div>
                  <div class="fr">
                    <img
                      @click="clickBtn('定位1', item.geom)"
                      src="@/assets/icon/bgfx_dw.png"
                    />
                  </div>
                </div>
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
        <!-- <div class="item">
                    <img src="@/assets/icon/icon02.png" />
                    <div>爆管分析</div>
                </div> -->
      </div>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref, computed, watch } from 'vue'
import { ElMessage } from 'element-plus'
import ManageService from '@/service/manage.service'
const props = defineProps({
  ExplosionAnalysisVisible: {
    type: Boolean,
    default: ''
  },
  ExplosionAnalysisAdd: {
    type: Object,
    default: {}
  }
})
const searchForm = ref({
  totle: 0,
  current: 1,
  size: 10
})
const tableData = ref({
  geom: {},
  point: {},
  rqLineList: [],
  rqPointList: []
})
// 深度监听 ExplosionAnalysisAdd 的变化
watch(
  () => props.ExplosionAnalysisAdd,
  (newVal, oldVal) => {
    console.log('ExplosionAnalysisAdd changed:', newVal)
    tableData.value = {
      geom: {},
      point: {},
      rqLineList: [],
      rqPointList: []
    }
    if (newVal.coordinate && newVal.coordinate.length === 2) {
      ManageService.post_booster({
        type: 'Point',
        crs: { type: 'name', properties: { name: 'EPSG:4490' } },
        coordinates: newVal.coordinate
      }).then((res) => {
        if (res.data && !res.data.geom && !res.data.point) {
          ElMessage({
            message: '未查询到有效数据！',
            type: 'error'
          })
          return
        }
        tableData.value = res.data
        emits('listenExplosionAnalysis', '加载爆管分析点', res.data)
      })
    }
    // 在这里你可以处理属性值的变化
  },
  { deep: true } // 启用深度监视
)
const emits = defineEmits([
  'update:ExplosionAnalysisVisible',
  'listenExplosionAnalysis'
])
const dialogVisible = computed({
  get: () => props.ExplosionAnalysisVisible,
  set: (val) => {
    emits('listenExplosionAnalysis', '关闭弹窗')
  }
})
const formInline = ref({})
const optionsFm = ref([
  {
    label: '阀门',
    value: '阀门'
  },
  {
    label: '管帽',
    value: '管帽'
  },
  {
    label: '气源点',
    value: '气源点'
  },
  {
    label: '三通',
    value: '三通'
  },
  {
    label: '弯头',
    value: '弯头'
  },
  {
    label: '直线点',
    value: '直线点'
  }
])
const clickBtn = (type, geom) => {
  if (type === '定位') {
    emits('listenExplosionAnalysis', type, geom.coordinates)
    return
  }
  if (type === '定位1') {
    emits('listenExplosionAnalysis', type, geom.coordinates[0])
    return
  }
  if (type === '清除结果') {
    // emits('listenExplosionAnalysis', type)
    tableData.value = {
      geom: {},
      point: {},
      rqLineList: [],
      rqPointList: []
    }
  }
  emits('listenExplosionAnalysis', type)
}
</script>
<style lang="scss" scoped>
.dia {
  color: #000;
  :deep(.el-form-item__label) {
    color: #fff;
  }
  & > :deep(div) {
    pointer-events: none;
  }

  :deep(.el-dialog) {
    pointer-events: auto !important;
    background: rgba(1, 25, 53, 0.8);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    border: 1px solid rgba(219, 238, 175, 0.2);
    color: #fff;
    position: absolute;
    border-radius: 4px;
    left: 10px;
    bottom: 0;

    .el-dialog__headerbtn .el-dialog__close,
    .el-dialog__title,
    .el-dialog__body {
      color: #fff;
    }
  }

  .con {
    display: flex;
    flex-wrap: wrap;
    margin: 0 10px;
    .body {
      width: 100%;
      .body-card {
        max-height: 320px;
        min-height: 320px;
        overflow-y: scroll;
        &::-webkit-scrollbar {
          display: none; /* Chrome, Safari, and Opera */
        }
      }
      .item {
        display: flex;
        justify-content: space-between;
        background-color: #054c50;
        height: 36px;
        align-items: center;
        padding: 0 10px;
        font-size: 14px;
        margin-bottom: 2px;
        .fl {
          .t {
            padding: 0 20px;
            font-size: 16px;
          }
          .s {
            padding: 0 5px;
            border: 1px solid #ccc;
          }
        }
        .fr {
          font-size: 0;
          img {
            cursor: pointer;
          }
        }
      }
      :deep(.el-tabs--border-card) {
        background: transparent;
        .el-tabs__header {
          background: transparent;
          .el-tabs__item.is-active {
            color: #fff;
            background-color: #409eff;
          }
          .el-tabs__item {
            color: #fff;
          }
        }
      }
    }
    // .item {
    //     width: 100px;
    //     height: 100px;
    //     color: #fff;
    //     border: 1px solid hsla(0, 0%, 100%, 0.4);
    //     border-radius: 5px;
    //     text-align: center;
    //     display: flex;
    //     align-content: center;
    //     flex-wrap: wrap;
    //     cursor: pointer;

    //     img {
    //         width: 40px;
    //         height: 40px;
    //         margin: 0 auto 10px;
    //     }

    //     div {
    //         width: 100%;
    //         font-size: 18px;
    //     }

    //     &:hover {
    //         border: 1px solid #409eff;
    //         color: #409eff;
    //     }
    // }
  }
}
</style>
